package co.edu.usbcali.egrapico.vista.tools;

public class MyIcon implements javax.swing.Icon {

    private double esc;
    private double del;
    private java.awt.RenderingHints renderHints;
    private String filename;
    private int heigth;
    private int width;

    public MyIcon(String filen, int W, int H) {
        super();
        heigth = H;
        width = W;
        this.filename = filen;
        this.esc = 1;
        this.del = 0;
        renderHints = new java.awt.RenderingHints(java.awt.RenderingHints.KEY_ANTIALIASING, java.awt.RenderingHints.VALUE_ANTIALIAS_ON);
        renderHints.put(java.awt.RenderingHints.KEY_FRACTIONALMETRICS, java.awt.RenderingHints.VALUE_FRACTIONALMETRICS_ON);
        renderHints.put(java.awt.RenderingHints.KEY_RENDERING, java.awt.RenderingHints.VALUE_RENDER_QUALITY);
    }

    public int getIconHeight() {
        return heigth;
    }

    public int getIconWidth() {
        return width;
    }

    public void UpEscale() {
        if (this.esc >= 0.999) {
            this.del = -0.05;
        }
        if (this.esc <= 0.05) {
            this.del = 0.05;
        }
        this.esc += this.del;
    }

    public double getesc() {
        return esc;
    }

    public String getFileName() {
        return filename;
    }

    public void paintIcon(java.awt.Component c, java.awt.Graphics g, int x, int y) {
        java.awt.Graphics2D g2d = (java.awt.Graphics2D) g;
        java.awt.geom.AffineTransform oldTransform = g2d.getTransform();
        java.awt.RenderingHints oldHints = g2d.getRenderingHints();

        g2d.setRenderingHints(renderHints);
        g2d.setColor(c.getForeground());

        javax.swing.ImageIcon ic = new javax.swing.ImageIcon(getClass().getResource(this.filename));
        java.awt.geom.AffineTransform trans = new java.awt.geom.AffineTransform();
        trans.concatenate(oldTransform);
        trans.setToScale(esc, esc);
        
        g2d.drawImage(ic.getImage(), trans, c);
        g2d.setTransform(oldTransform);
        g2d.setRenderingHints(oldHints);
    }
}